package com.hghivln.erpwarehouse.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hghivln.erpwarehouse.business.entity.Customer;
import com.hghivln.erpwarehouse.business.mapper.CustomerMapper;
import com.hghivln.erpwarehouse.business.service.CustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hghivln.erpwarehouse.business.vo.CustomerVo;
import com.hghivln.erpwarehouse.system.common.lang.Constant;
import com.hghivln.erpwarehouse.system.common.lang.DataGridlView;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hghivln
 //* @since 2021-07-10
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

    @Override
    public DataGridlView QueryAllCustomer(CustomerVo customerVo) {
        Page<Customer> page = new Page<>(customerVo.getPage(),customerVo.getLimit());
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.like(!StringUtils.isEmpty(customerVo.getCustomername()),"customername",customerVo.getCustomername());
        qw.like(!StringUtils.isEmpty(customerVo.getConnectionpersion()),"connectionpersion",customerVo.getConnectionpersion());
        qw.like(!StringUtils.isEmpty(customerVo.getPhone()),"phone", customerVo.getPhone());
        getBaseMapper().selectPage(page,qw);
        return new DataGridlView(page.getTotal(),page.getRecords());
    }

    @Override
    public Customer addCustomer(Customer customer) {
        getBaseMapper().insert(customer);
        return customer;
    }

    @Override
    public Customer updateCustomer(Customer customer) {
        getBaseMapper().updateById(customer);
        return customer;
    }

    @Override
    public DataGridlView getAllAvailableCustomer() {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("available", Constant.AVAILABLE_TRUE);
        List<Customer> list = getBaseMapper().selectList(qw);
        return new DataGridlView(list);
    }

    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }
}
